<?php
namespace Admin\Model;
use Think\Model;
class TeacherModel extends Model 
{
	protected $insertFields = array('teacher_name','teacher_tel','teacher_project','teacher_price','company_id');
	protected $updateFields = array('id','teacher_name','teacher_tel','teacher_project','teacher_price');
	protected $_validate = array(
		array('teacher_name', '1,255', 'l教师名的值最长不能超过 255 个字符！', 2, 'length', 3),
		array('teacher_tel', '1,255', '教师电话的值最长不能超过 255 个字符！', 2, 'length', 3),
		array('teacher_project', '1,255', '教师项目的值最长不能超过 255 个字符！', 2, 'length', 3),
		array('teacher_price', '1,255', '教师价格的值最长不能超过 255 个字符！', 2, 'length', 3),
	);
	public function search($pageSize = 20)
	{
		/**************************************** 搜索 ****************************************/
		$where = array();
		if($teacher_name = I('get.teacher_name'))
			$where['teacher_name'] = array('like', "%$teacher_name%");
		if($teacher_tel = I('get.teacher_tel'))
			$where['teacher_tel'] = array('like', "%$teacher_tel%");
        //对应瑜伽馆
        if(intval(session('admin.company_id')) !==1){
            $where['company_id'] = ['eq',session('admin.company_id')];
        }
		/************************************* 翻页 ****************************************/
		$count = $this->alias('a')->where($where)->count();
		$page = new \Think\Page($count, $pageSize);
		// 配置翻页的样式
		$page->setConfig('prev', '上一页');
		$page->setConfig('next', '下一页');
		$data['page'] = $page->show();
		/************************************** 取数据 ******************************************/
		$data['data'] = $this->alias('a')->where($where)->group('a.id')->limit($page->firstRow.','.$page->listRows)->select();
		return $data;
	}
	// 添加前
	protected function _before_insert(&$data, $option)
	{
        $data['company_id'] = session('admin.company_id');
    }
	// 修改前
	protected function _before_update(&$data, $option)
	{
	}
	// 删除前
	protected function _before_delete($option)
	{
		if(is_array($option['where']['id']))
		{
			$this->error = '不支持批量删除';
			return FALSE;
		}
	}
	/************************************ 其他方法 ********************************************/
}